package de.preisrobot.entity;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OrderColumn;
import javax.persistence.Table;

@Entity
@Table(name = "tb_category")
//NamedQueries({
//      @NamedQuery(name = "TreeNode.findAllTree", 
//              query = "select p from TreeNode p  " +
//                    "LEFT JOIN fetch p.parentNode"),
//    })

public class Tb_Category implements Serializable
{
   /**
    * 
    */
   private static final long serialVersionUID = 1L;


   @Id
   @GeneratedValue(strategy = GenerationType.AUTO)
   private long id;
   
//   private Long parent;
   
   @ManyToOne(cascade=CascadeType.ALL)
   @JoinColumn(name = "parent" ,insertable=true, updatable=true)
   private Tb_Category parentCategory;

   @OneToMany(cascade={CascadeType.MERGE, CascadeType.REFRESH, CascadeType.PERSIST}, mappedBy="parentCategory")
   @OrderColumn(name="sortierung")  
   private List<Tb_Category> children = new ArrayList<Tb_Category>();
   
//   @Column(nullable=false, unique=true)
   private String name;
   
   private String link;
   
   private int orderid;

   public Tb_Category()
   {
    
   }
 

   public List<Tb_Category> getChildren()
   {
      return children;
   }

   public void setChildren(List<Tb_Category> children)
   {
      this.children = children;
   }

   public String getName()
   {
      return name;
   }

   public void setName(String name)
   {
      this.name = name;
   }

   public int getOrder()
   {
      return orderid;
   }

   public void setOrder(int order)
   {
      this.orderid = order;
   }

   public void setId(Long id)
   {
      this.id = id;
   }

   public Long getId()
   {
      return id;
   }


   public void setParentCategory(Tb_Category parentCategory)
   {
      this.parentCategory = parentCategory;
   }


   public Tb_Category getParentCategory()
   {
      return parentCategory;
   }


   public void setLink(String link)
   {
      this.link = link;
   }


   public String getLink()
   {
      return link;
   }


//   public void setParent(Long parent)
//   {
//      this.parent = parent;
//   }
//
//
//   public Long getParent()
//   {
//      return parent;
//   }


 
   
}
